package com.loop.unclelend.pro

import com.loop.unclelend.MyApplication
import com.loop.unclelend.base.BasePresenter
import com.loop.unclelend.network.IHttpCallback
import org.json.JSONObject

/**
 * UncleLend
 * @Author wwdeng
 * @CreateTime: 2024/9/3 16:02
 * @Annotation：
 */
abstract class ProPresenter(private val iView: IProView): BasePresenter() {

    fun getString(strId: Int): String{
        return MyApplication.app.getString(strId)
    }

    fun doPostAction(httpUrl: String,params: JSONObject,callback: IHttpCallback){
        iView.getAct().doPostAction(httpUrl, params,object : IHttpCallback{
            override fun onRequestSuccess(data: JSONObject) {
                when(data.optInt("code")) {
                    0 -> {//成功
                       callback.onRequestSuccess(data)
                    }
                    else -> {
                        callback.onRequestError(data)
                        val msg = data.optString("msg")
                        iView.showUncleToast(msg)
                        iView.hideUncleLoading()
                    }
                }
            }

            override fun onRequestError(error: JSONObject) {
                callback.onRequestError(error)
                iView.showUncleToast(error.optString("errorMsg"))
                iView.hideUncleLoading()
            }

            override fun onRequestFinish() {
                callback.onRequestFinish()
            }
        })
    }

}